package com.longe.netty.protobufTwo;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * 服务端的 handler
 */
public class NettyProtoBufServerHandler extends SimpleChannelInboundHandler<MyMessageData.MyMessage> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MyMessageData.MyMessage msg) {
        //根据dataType 来显示不同的信息
        MyMessageData.MyMessage.DataType dataType = msg.getDataType();
        if (dataType == MyMessageData.MyMessage.DataType.StudentType) {

            MyMessageData.Student student = msg.getStudent();
            System.err.println("学生id=" + student.getId() + " 学生名字=" + student.getName());

        } else if (dataType == MyMessageData.MyMessage.DataType.TeacherType) {
            MyMessageData.Teacher teacher = msg.getTeacher();
            System.err.println("老师的名字=" + teacher.getName() + " 年龄=" + teacher.getAge());
        } else {
            System.err.println("传输的类型不正确");
        }
    }
}
